IHG.Preferences = {
	set: function(key, value) {
		throw IHG.BadMethodCall('No Preferences-storage available');
	},
	get: function(key, defaultValue) {
		throw IHG.BadMethodCall('No Preferences-storage available');
	}
};

/* Greasemonkey & Greasekit eigen settings-implementatie */
if(typeof GM_setValue != 'undefined') {
	IHG.Preferences.set = function(key, value) {
		return GM_setValue(key, value);
	}
	
	IHG.Preferences.get = function(key, defaultValue) {
		return GM_getValue(key) || defaultValue;
	}
}
/* Terugvallen op het treurige cookie gebeuren */
else if(typeof document.cookie != 'undefined') {
	IHG.Preferences.set = function(key, value) {
		var expireDate = new Date((new Date()).getTime() + 60 * 60 * 365);
		document.cookie = 'ihg_' + key + '=' + escape(value) 
			+ ';expires=' + expireDate.toGMTString()
			+ ';path=/';
	}
	
	IHG.Preferences.get = function(key, defaultValue) {
		var cookies = document.cookie.split(';');
		var name, value;
		for(var i = 0; i < cookies.length; i++) {
			var cookie = cookies[i].split('=');
			if(cookie[0].replace(/^\s+|\s+$/g, '') == 'ihg_' + key) {
				return unescape(cookie[1]);
			}
		}
		
		return defaultValue;
	}
}